package com.czkj.hwz.decorate.Activity;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.blankj.utilcode.util.ToastUtils;
import com.czkj.hwz.decorate.IMP.HttpDoImp;
import com.czkj.hwz.decorate.base.BaseActivity;
import com.czkj.hwz.decorate.bean.User;
import com.czkj.hwz.decorate.control.UserCtl;
import com.czkj.hwz.decorate.R;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_user_register)
public class UserRegisterActivity extends BaseActivity implements HttpDoImp {
    private User mUser;
    private UserCtl mUserCtl;
    @ViewInject(R.id.edt_account)
    private EditText edt_account;
    @ViewInject(R.id.edt_password)
    private EditText edt_password;
    @ViewInject(R.id.edt_smscode)
    private EditText edt_smscode;
    @ViewInject(R.id.bt_register)
    private Button bt_register;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mUserCtl = new UserCtl(this);
        bt_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mUser=new User();
                mUser.setAccount(edt_account.getText().toString());
                mUser.setPassword(edt_password.getText().toString());
                mUser.setSmscode(edt_smscode.getText().toString());
                mUserCtl.userRegister(mUser);
            }
        });


        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public void onSuccess(String flag, Object... objects) {

        switch (flag) {
            case "indexGet":
                String resultGet = (String) objects[0];
                Toast.makeText(this, resultGet, Toast.LENGTH_SHORT).show();
                break;
            case "userRegister":
                String result = (String) objects[0];
                Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
                break;
        }

    }

    @Override
    public void onError(String errinfo) {
        ToastUtils.showLong(errinfo);
    }

    @Override
    protected void onResume() {
        super.onResume();

    }



}
